package cn.epsilon3.service.thirdAuthLogin.impl;

import cn.epsilon3.constant.SSOChannelEnum;
import cn.epsilon3.domain.e3.dto.ThirdAuthLoginDTO;
import cn.epsilon3.domain.e3.vo.E3ThirdUserInfoShareVO;
import cn.epsilon3.exception.Epsilon3ReturnException;
import cn.epsilon3.utils.ThirdSSOUtils;
import cn.epsilon3.service.thirdAuthLogin.E3ThirdAuthReqService;
import org.springframework.stereotype.Service;

/**
 * 第三方平台请求
 *
 * @author epsilon3
 * @date 2023-10-21
 */
@Service
public class E3ThirdAuthReqServiceImpl implements E3ThirdAuthReqService {

    @Override
    public E3ThirdUserInfoShareVO to(ThirdAuthLoginDTO thirdAuthLoginDTO) {
        String channel = thirdAuthLoginDTO.getChannel();
        SSOChannelEnum ssoChannelEnum = SSOChannelEnum.getChannel(channel);
        switch (ssoChannelEnum) {
            case ALIPAY_CHANNEL:
                return ThirdSSOUtils.toAlipay(thirdAuthLoginDTO);
            case GITHUB_CHANNEL:
                return ThirdSSOUtils.toGithub(thirdAuthLoginDTO);
            default:
                throw new Epsilon3ReturnException("未知的渠道类型");
        }
    }
}
